//package com.example.kafkademo.interceptor;
//
//import org.apache.kafka.clients.consumer.ConsumerInterceptor;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.apache.kafka.clients.consumer.ConsumerRecords;
//import org.apache.kafka.clients.consumer.OffsetAndMetadata;
//import org.apache.kafka.common.TopicPartition;
//
//import java.util.Map;
//
///**
// * @author yanyun zhu
// * @version 1.0
// * @date 2021/12/28 16:23
// */
//public class AvgLatencyConsumerInterceptor implements ConsumerInterceptor<String, String> {
//
//
//    private Jedis jedis; // 省略 Jedis 初始化
//
//
//    @Override
//    public ConsumerRecords<String, String> onConsume(ConsumerRecords<String, String> records) {
//        long lantency = 0L;
//        for (ConsumerRecord<String, String> record : records) {
//            lantency += (System.currentTimeMillis() - record.timestamp());
//        }
//        jedis.incrBy("totalLatency", lantency);
//        long totalLatency = Long.parseLong(jedis.get("totalLatency"));
//        long totalSentMsgs = Long.parseLong(jedis.get("totalSentMessage"));
//        jedis.set("avgLatency", String.valueOf(totalLatency / totalSentMsgs));
//        return records;
//    }
//
//
//    @Override
//    public void onCommit(Map<TopicPartition, OffsetAndMetadata> offsets) {
//    }
//
//
//    @Override
//    public void close() {
//    }
//
//
//    @Override
//    public void configure(Map<String, ?> configs) {
//
//    }
//}